// 云函数入口文件
const cloud = require('wx-server-sdk')
const rp = require('request-promise')

cloud.init()
const db = cloud.database()
let dbTime = db.serverDate()

// 云函数入口函数
exports.main = async(event, context) => {
  //   订阅消息
  const {
    OPENID
  } = cloud.getWXContext()

  try {
    const result = await cloud.openapi.subscribeMessage.send({
      touser: OPENID,
      page: `/pages/blog-comment/blog-comment?id=${event.blogId}`,
      data: {
        time1: {
          value: event.createTime,
        },
        phrase2: {
          value: "评价完成",
        },
        thing3: {
          value: event.content
        },
      },
      templateId: 'FW78NqwFbCW4kIEZKLEnkJoTxTLxGu0qq3i-vAf2ivo'
    })

    return result
    
  } catch (err) {
    console.log(err);
    return err;
  }

}